package com.goodwill.androidtest.compress;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;

import com.goodwill.androidtest.R;
import com.goodwill.androidtest.utils.CompressUtil;
import com.goodwill.androidtest.utils.FileUtils;

public class GZIPCompressTestActivity extends AppCompatActivity {
    private static final String TAG = "GZIPCompressTest";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gzipcompress_test);


//        testDncode_();
        testDncode2_();
//        testEncode_();
    }

    private void testDncode2_() {
        String content = FileUtils.readAssetsFile(this, "nock_evalute_module_encode2.json");
        if (!TextUtils.isEmpty(content)) {
            Log.i(TAG, "压缩前\n : " + content + "\n");
            String unCompress = CompressUtil.unCompress(content);
            Log.i(TAG, "解压缩后\n : " + unCompress + "\n");
        }
    }

    //nock_evalute_module_encode.json
    private void testDncode_() {
        String content = FileUtils.readAssetsFile(this, "nock_evalute_module_encode2.json");
        if (!TextUtils.isEmpty(content)) {
            Log.i(TAG, "压缩前\n : " + content + "\n");
            String unCompress = CompressUtil.unCompress(content);
            Log.i(TAG, "解压缩后\n : " + unCompress + "\n");
        }
    }

    private void testEncode_() {
        String content = FileUtils.readAssetsFile(this, "nock_evalute_module.json");
        if (!TextUtils.isEmpty(content)) {
            Log.i(TAG, "压缩前\n : " + content + "\n");
            //对图像字符串进行GZIP压缩后再进行Base64压缩
            String encodeToString = Base64.encodeToString(CompressUtil.compress(content.getBytes()), Base64.DEFAULT);
//            byte[] compress = CompressUtil.compress(content.getBytes());
            Log.i(TAG, "压缩后\n : " + encodeToString + "\n");
            String unCompress = CompressUtil.unCompress(encodeToString);
            Log.i(TAG, "解压缩后\n : " + unCompress + "\n");
        }
    }
}
